function [newDag newData newNames newNodeSizes] = fixTopology(dag, data, names, node_sizes)
    %scan the connections
    conn=[];
    for ( i = 1:size(dag, 1))
        for ( j = 1:size(dag, 2))
            if(dag(i,j)==1)
                if(isempty(conn))
                    conn=[names(i),names(j)];
                else
                    conn=[conn; names(i), names(j)];
                end;
            end;
        end;
    end;
    [newDag newNames] = mk_adj_mat(conn, names, 1);
    newData=[];
    newNodeSizes=[];
    
    for(i = 1:size(newNames,2))
        display(i);
        display(strmatch(newNames(1,i),names));
        newData=[newData,data(:,strmatch(newNames(1,i),names))];
        newNodeSizes=[newNodeSizes, node_sizes(1,i)];
    end
end